<?php
class ui_save_show extends ui {
	/**
	 * @param Object $S
	 * @param Array $param = null
	 * 		$_GET['t']		// encodeURIComponent 的 title
	 */
	public function __construct($S, $param) {
		parent::__construct();
		
		if ($this->uid) {
			// 用户信息
			$data_user = new data_user();
			$me = $data_user->one($this->uid);
			$return['nick']		= $me['nickname'];
			
			// 检查各账号的登陆情况
			$return['is_login'] = '';
			$return['not_login'] = '';
			$is_login = '';
			if ($me['weibo_id']) {
				if ($me['weibo_token']) {
					$return['is_login'][] = array (
						'name'	=> '新浪微博',
						'img'		=> 'http://uread.me/images/icon_weibo_16.png',
					);
                                        $is_login[] = 'weibo';
				} else {
					$return['not_login'][] = array (
						'flag'		=> 'weibo',
						'img'		=> 'http://uread.me/images/icon_weibo_16_grey.png',
						'login_img'	=> 'http://uread.me/images/login_weibo.png',
					);
				}
			}
			if ($me['renren_id']) {
				if ($me['renren_token']) {
					$return['is_login'][] = array (
						'name'	=> '人人网',
						'img'		=> 'http://uread.me/images/icon_renren_16.png',
					);
                                        $is_login[] = 'renren';
				} else {
					$return['not_login'][] = array (
						'flag'		=> 'renren',
						'img'		=> 'http://uread.me/images/icon_renren_16_grey.png',
						'login_img'	=> 'http://uread.me/images/login_renren.png',
					);
				}
			}
			if ($me['kaixin001_id']) {
				if ($me['kaixin001_token']) {
					$return['is_login'][] = array (
						'name'	=> '开心网',
						'img'		=> 'http://uread.me/images/icon_kaixin001_16.png',
					);
                                        $is_login[] = 'kaixin001';
				} else {
					$return['not_login'][] = array (
						'flag'		=> 'kaixin001',
						'img'		=> 'http://uread.me/images/icon_kaixin001_16_grey.png',
						'login_img'	=> 'http://uread.me/images/login_kaixin001.png',
					);
				}
			}
			if ($me['qqwb_id']) {
				if ($me['qqwb_token']) {
					$return['is_login'][] = array (
						'name'	=> '腾讯微博',
						'img'		=> 'http://uread.me/images/icon_qqwb_16.png',
					);
                                        $is_login[] = 'qqwb';
				} else {
					$return['not_login'][] = array (
						'flag'		=> 'qqwb',
						'img'		=> 'http://uread.me/images/icon_qqwb_16_grey.png',
						'login_img'	=> 'http://uread.me/images/login_qqwb.png',
					);
				}
			}
			
			// circle圈子
			$data_circle = new data_circle();
			$circles = $data_circle->ls($this->uid, 'member', 'private');
			if (is_array($circles)) {
				foreach ($circles as $v) {
					$return['circles'][] = array (
						'id'		=> $v['id'],
						'name'	=> $v['title'],
						'privacy'	=> $v['privacy']
					);
				}
			}
			
			// friends部分：用户的好友列表
			$data_friend = new data_friend();
                        
			$friends = $data_friend->ls($this->uid, 'all', $is_login, 0, 0);	// 列出全部好友，按total recommends send排序
			if (is_array($friends)) {
				if (count($return['is_login']) > 1) {		// 如果登陆的社交账号类型超过1个，那么需要显示好友的社交账号类型
					$is_show_socials = true;
				} else {
					$is_show_socials = false;
				}
				foreach ($friends as $v) {
					$socials = '';
					if ($is_show_socials) {
						if ($v['weibo_id'])		$socials[] = 'weibo';
						if ($v['renren_id'])		$socials[] = 'renren';
						if ($v['kaixin001_id'])	$socials[] = 'kaixin001';
						if ($v['qqwb_id'])		$socials[] = 'qqwb';
						if (is_array($socials)) $socials = implode ('_', $socials);		// 构造好友的绑定账号类型。字符串用“_”连接
					}
					$return['friends'][] = array (
						'id'		=> $v['friend_id'],
						'name'	=> $v['nickname'],
						'socials'	=> $socials,
					);
				}
			}
			
			$json = json_encode($return);
			if ($_GET['br'] == 'ie') {
				$data = "UM_OB.jsonp_callback(".$json.");";	// 直接带入json对象
			} else {
				$data = $json;
			}
			$S->assign('data', $data);
		}
	}
}
?>